// detect numeric math expressions to execute right away
function mathexp(t)
{
// chop out variables
var noconst = t.replace(/\b(PI|E|LOG2E|LOG10E|LN2|LN10|SQRT2|SQRT1_2|pi)\b/g, "_");
// experiment: also allow "longvarname="
var noconst = noconst.replace(/^[a-zA-Z_]+\s*=/, "a=");
// it's only an expression if it ends with a digit, paren, or variable
if (!noconst.match(/\b[a-z]$|[_\d\)]$/)) return false;
// chop out function names
var nofunc = noconst.replace(/\b(ln|log10|log2|hex|oct|bin|abs|acos|asin|atan|atan2|ceil|cos|exp|floor|log|max|min|pow|random|round|sin|sqrt|tan)\(/g, "(");
// it's only an expression if it begins with a digit, paren, or variable - or a minus
if (!nofunc.match(/^[a-z_]\b|^[x\d\-\.\(]/)) return false;
// detect numbers
var nonum = nofunc.replace(/\b(\d+(\.\d*)?)([eE][+-]?\d+)?\b/g, "1");
var nonum = nonum.replace(/(\.\d+)([eE][+-]?\d+)?\b/g, "1");
// remove spsaces
var nospace = nonum.replace(/\s/g, "");
// only operators and recognized things are allowed
if (!nospace.match(/^[1_a-z\*\-\+\/\(\),=]+$/)) return false;
// constants cannot touch
if (nospace.match(/[1_a-z\)][1_a-z\(]/)) return false;
// operators cannot touch
if (nospace.match(/[\*\-\+\/][\*\+\/=]/)) return false;